package gw.com.android.ui.home;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Typeface;
import android.os.Build;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gwtsz.gts2.hx.R;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import gw.com.android.app.GTConfig;
import gw.com.android.presenter.http.HomeTradeVaneRequest;
import gw.com.android.utils.CacheUtils;
import gw.com.android.utils.FontUtils;

/**
 * 首頁，交易风向标
 * <p>
 * 看来这里是给他构建数据的
 */
public class HomeTradingVaneView extends RelativeLayout {

    public static boolean ifDebug = true;//如果打开了debug模式，则真实数据被拦截，程序将会读取假数据；这么设计是为了验证中文文案的正确性

    private static boolean ifGuideClosed = false;
    private String ifGuideClosedTag = "ifGuideClosed";

    private boolean ifAnimatorRunning = false;
    private Context mContext;

    public HomeTradingVaneView(Context context) {
        this(context, null);
    }

    public HomeTradingVaneView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public HomeTradingVaneView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        font = FontUtils.getDIN_MediumFont(context);
        ifDebug = context.getResources().getBoolean(R.bool.ifCardDebug);
    }

    private LinearLayout ll_no_data, ll_card1, ll_card2;
    private ImageView iv_card_guidance;
    private RelativeLayout rl_card_guidance;

    private double p1, p2, p1_2, p2_2;//第一个卡片的正反面数据

    private double q1, q2, q1_2, q2_2;//第二个卡片的正反面数据

    private void initViews() {
        ll_no_data = findViewById(R.id.ll_no_data);
        ll_card1 = findViewById(R.id.ll_card1);
        ll_card2 = findViewById(R.id.ll_card2);
        iv_card_guidance = findViewById(R.id.iv_card_guidance);
        rl_card_guidance = findViewById(R.id.rl_card_guidance);
        guideShow();//默认显示
        // 一次运行只显示一次
        View.OnClickListener guideDisappearLis = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CacheUtils.writeFile(ifGuideClosedTag, "true");
                clearCardGuidance();
            }
        };
        rl_card_guidance.setOnClickListener(guideDisappearLis);
    }

    private boolean ifDisappearing = false;

    private void clearCardGuidance() {
        iv_card_guidance.clearAnimation();
        if (ifDisappearing) return;
        ifDisappearing = true;
        ObjectAnimator alpha = ObjectAnimator.ofFloat(iv_card_guidance, "alpha", 1, 0);
        alpha.setDuration(300);
        alpha.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                Log.d("onAnimationEndTag", "执行");
                ifDisappearing = false;
                guideHide();
            }
        });
        alpha.start();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        initData();
        initViews();
        refreshCard();
    }

    private void refreshCard() {
        //第一张卡片
        CardViewHolder cardViewHolder = createViewHolder(R.id.fl_main, R.id.ll_main, R.id.ll_main_2, R.id.annulusPieView,
                R.id.annulusPieView_2, R.id.tv_p1, R.id.tv_p2, R.id.tv_p1_2, R.id.tv_p2_2, R.id.tv_suggests, R.id.tv_suggests_2, R.id.v_point_sell_1, R.id.v_point_buy_1, R.id.v_point_sell_2, R.id.v_point_buy_2);
        initViewBuySell(p1, p2, p1_2, p2_2, cardViewHolder);
        refreshColor(cardViewHolder);//由于要跟随系统的绿涨红跌或者 红涨绿跌，所以要执行颜色更新

        //第二张卡片
        CardViewHolder cardViewHolderXXX = createViewHolder(R.id.fl_main_b, R.id.ll_main_b, R.id.ll_main_2_b, R.id.annulusPieView_b,
                R.id.annulusPieView_2_b, R.id.tv_p1_b, R.id.tv_p2_b, R.id.tv_p1_2_b, R.id.tv_p2_2_b, R.id.tv_suggests_b, R.id.tv_suggests_2_b, -1, -1, -1, -1);
        initViewOpenClose(q1, q2, q1_2, q2_2, cardViewHolderXXX);
    }

    //先把颜色配置准备好；colors.xml里面配置了4种颜色;
    //第一张卡片要支持 刷新颜色配置
    public void refreshColor(CardViewHolder cardViewHolder) {
        int color_annulus_red = getResources().getColor(R.color.color_annulus_red);
        int color_annulus_green = getResources().getColor(R.color.color_annulus_green);
        int color_annulus_red_shadow = getResources().getColor(R.color.color_annulus_red_shadow);
        int color_annulus_green_shadow = getResources().getColor(R.color.color_annulus_green_shadow);

        if (GTConfig.instance().getPrefColorConfig().equals(GTConfig.COLOR_GREEN_RISE)) {//绿涨红跌
            // 先把圆弧的颜色改了
            cardViewHolder.annulusPieView.setAnnulusColor1(color_annulus_red);
            cardViewHolder.annulusPieView.setAnnulusColor2(color_annulus_green);
            cardViewHolder.annulusPieView.setShadowColor1(color_annulus_red_shadow);
            cardViewHolder.annulusPieView.setShadowColor2(color_annulus_green_shadow);

            cardViewHolder.annulusPieView_2.setAnnulusColor1(color_annulus_red);
            cardViewHolder.annulusPieView_2.setAnnulusColor2(color_annulus_green);
            cardViewHolder.annulusPieView_2.setShadowColor1(color_annulus_red_shadow);
            cardViewHolder.annulusPieView_2.setShadowColor2(color_annulus_green_shadow);

            cardViewHolder.v_point_buy_1.setColors(color_annulus_green, color_annulus_green_shadow);
            cardViewHolder.v_point_sell_1.setColors(color_annulus_red, color_annulus_red_shadow);
            cardViewHolder.v_point_buy_2.setColors(color_annulus_green, color_annulus_green_shadow);
            cardViewHolder.v_point_sell_2.setColors(color_annulus_red, color_annulus_red_shadow);

        } else {// 红涨绿跌
            cardViewHolder.annulusPieView.setAnnulusColor2(color_annulus_red);
            cardViewHolder.annulusPieView.setAnnulusColor1(color_annulus_green);
            cardViewHolder.annulusPieView.setShadowColor2(color_annulus_red_shadow);
            cardViewHolder.annulusPieView.setShadowColor1(color_annulus_green_shadow);

            cardViewHolder.annulusPieView_2.setAnnulusColor2(color_annulus_red);
            cardViewHolder.annulusPieView_2.setAnnulusColor1(color_annulus_green);
            cardViewHolder.annulusPieView_2.setShadowColor2(color_annulus_red_shadow);
            cardViewHolder.annulusPieView_2.setShadowColor1(color_annulus_green_shadow);

            cardViewHolder.v_point_buy_1.setColors(color_annulus_red, color_annulus_red_shadow);
            cardViewHolder.v_point_sell_1.setColors(color_annulus_green, color_annulus_green_shadow);
            cardViewHolder.v_point_buy_2.setColors(color_annulus_red, color_annulus_red_shadow);
            cardViewHolder.v_point_sell_2.setColors(color_annulus_green, color_annulus_green_shadow);
        }
    }

    private CardViewHolder createViewHolder(int fl_mainR, int ll_mainR, int ll_main2R, int annulusPieViewR, int annulusPieView2R, int tv_p1R, int tv_p2R, int tv_p1_2R, int tv_p2_2R,
                                            int tv_suggestR, int tv_suggest_2R, int v_point_sell_1R, int v_point_buy_1R, int v_point_sell_2R, int v_point_buy_2R) {
        FrameLayout fl_main = (FrameLayout) findViewById(fl_mainR);
        LinearLayout ll_main = (LinearLayout) findViewById(ll_mainR);
        LinearLayout ll_main_2 = (LinearLayout) findViewById(ll_main2R);
        AnnulusPie annulusPieView = (AnnulusPie) findViewById(annulusPieViewR);
        AnnulusPie annulusPieView_2 = (AnnulusPie) findViewById(annulusPieView2R);
        TextView tv_p1 = (TextView) findViewById(tv_p1R);
        TextView tv_p2 = (TextView) findViewById(tv_p2R);
        TextView tv_p1_2 = (TextView) findViewById(tv_p1_2R);
        TextView tv_p2_2 = (TextView) findViewById(tv_p2_2R);

        CircleWithShadow v_point_sell_1 = findViewById(v_point_sell_1R);
        CircleWithShadow v_point_buy_1 = findViewById(v_point_buy_1R);
        CircleWithShadow v_point_sell_2 = findViewById(v_point_sell_2R);
        CircleWithShadow v_point_buy_2 = findViewById(v_point_buy_2R);

        //还有4个文案
        TextView tv_suggest = (TextView) findViewById(tv_suggestR);
        TextView tv_suggest_2 = (TextView) findViewById(tv_suggest_2R);

        CardViewHolder cardViewHolder = new CardViewHolder()
                .fl_main(fl_main)
                .ll_main(ll_main, ll_main_2)
                .annulusPieView(annulusPieView, annulusPieView_2)
                .tv_p(tv_p1, tv_p2)
                .tv_p2(tv_p1_2, tv_p2_2)
                .tv_suggests(tv_suggest, tv_suggest_2)
                .v_point(v_point_sell_1, v_point_buy_1, v_point_sell_2, v_point_buy_2);
        return cardViewHolder;
    }

    class CardViewHolder {//卡片布局的内部组件

        int pageIndex = 0;//标记当前旋转到了哪一面,0正面，1反面

        FrameLayout fl_main;//卡片最外层布局
        LinearLayout ll_main, ll_main_2;//正面/反面的布局
        AnnulusPie annulusPieView, annulusPieView_2;//正面/反面的圆环图
        TextView tv_p1, tv_p2;//正面的两个百分比数字
        TextView tv_p1_2, tv_p2_2;//反面的两个百分比数字
        TextView tv_suggests, tv_suggest_2;//正反的两个中文文案
        CircleWithShadow v_point_sell_1, v_point_buy_1, v_point_sell_2, v_point_buy_2;//小圆点

        public CardViewHolder() {

        }

        public CardViewHolder v_point(CircleWithShadow v_point_sell_1, CircleWithShadow v_point_buy_1, CircleWithShadow v_point_sell_2, CircleWithShadow v_point_buy_2) {
            this.v_point_sell_1 = v_point_sell_1;
            this.v_point_buy_1 = v_point_buy_1;
            this.v_point_sell_2 = v_point_sell_2;
            this.v_point_buy_2 = v_point_buy_2;
            return this;
        }

        public CardViewHolder fl_main(FrameLayout fl_main) {
            this.fl_main = fl_main;
            return this;
        }

        public CardViewHolder ll_main(LinearLayout ll_main, LinearLayout ll_main_2) {
            this.ll_main = ll_main;
            this.ll_main_2 = ll_main_2;
            return this;
        }

        public CardViewHolder annulusPieView(AnnulusPie annulusPieView, AnnulusPie annulusPieView_2) {
            this.annulusPieView = annulusPieView;
            this.annulusPieView_2 = annulusPieView_2;
            return this;
        }

        public CardViewHolder tv_p(TextView tv_p1, TextView tv_p2) {
            this.tv_p1 = tv_p1;
            this.tv_p2 = tv_p2;
            return this;
        }

        public CardViewHolder tv_p2(TextView tv_p1_2, TextView tv_p2_2) {
            this.tv_p1_2 = tv_p1_2;
            this.tv_p2_2 = tv_p2_2;
            return this;
        }

        public CardViewHolder tv_suggests(TextView tv_suggest, TextView tv_suggest_2) {
            this.tv_suggests = tv_suggest;
            this.tv_suggest_2 = tv_suggest_2;
            return this;
        }
    }

    private String makePercentStr(double v) {
        return Math.round(v * 100) + "%";
    }

    private void initView(double v1, double v2, double v1_2, double v2_2, final CardViewHolder holder) {
        holder.annulusPieView.setValues((float) v1, (float) v2);
        holder.annulusPieView.postInvalidate();
        holder.tv_p1.setText(makePercentStr(v1));
        holder.tv_p2.setText(makePercentStr(v2));

        //给4个百分比 设置特殊字体
        holder.tv_p1.setTypeface(font);
        holder.tv_p2.setTypeface(font);
        holder.tv_p1_2.setTypeface(font);
        holder.tv_p2_2.setTypeface(font);

        holder.tv_p1_2.setText(makePercentStr(v1_2));
        holder.tv_p2_2.setText(Math.round(v2_2 * 100) + "%");

        //卡片环形数据
        holder.annulusPieView_2.setValues((float) v1_2, (float) v2_2);
        holder.annulusPieView_2.postInvalidate();

        holder.ll_main.setRotationY(0);
        holder.ll_main_2.setRotationY(180);
        holder.ll_main.setAlpha(1);
        holder.ll_main_2.setAlpha(0);

        setAnimators();
        setCameraDistance(holder.ll_main, holder.ll_main_2);

        //翻转事件
        holder.fl_main.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ifAnimatorRunning) return;
                if (holder.pageIndex == 0) {
                    flipCard(holder, holder.ll_main, holder.ll_main_2, holder.pageIndex);
                    holder.pageIndex++;
                } else {
                    flipCard(holder, holder.ll_main, holder.ll_main_2, holder.pageIndex);
                    holder.pageIndex--;
                }
            }
        });
    }

    /**
     * 多空
     *
     * @param v1
     * @param v2
     * @param v1_2
     * @param v2_2
     * @param holder
     */
    private void initViewBuySell(double v1, double v2, double v1_2, double v2_2, final CardViewHolder holder) {
        initView(v1, v2, v1_2, v2_2, holder);
        //中文文案
        refreshSuggestBuySell((float) v1, (float) v2, holder.tv_suggests);//正面
        refreshSuggestBuySell((float) v1_2, (float) v2_2, holder.tv_suggest_2);//反
    }

    /**
     * 持仓
     */
    private void initViewOpenClose(double v1, double v2, double v1_2, double v2_2, final CardViewHolder holder) {
        initView(v1, v2, v1_2, v2_2, holder);
        //中文文案
        refreshSuggestOpenClose((float) v1, (float) v2, holder.tv_suggests);//正面
        refreshSuggestOpenClose((float) v1_2, (float) v2_2, holder.tv_suggest_2);////反
    }

    Typeface font = null;

    public void refresh(HomeTradeVaneRequest.HomeTradeVaneData data) {
        Log.d("tradingVaneTag", "(data == null):" + (data == null) + ";ifDebug:" + ifDebug);
        if (ifDebug) {
            initData();
            refreshUpdateTime("模拟数据！");
            refreshCard();
        } else {
            if (data == null) {
                //还要判断是否有缓存数据
                ll_card1.setVisibility(GONE);
                ll_card2.setVisibility(GONE);
                ll_no_data.setVisibility(VISIBLE);
                guideHide();
                return;
            } else {
                ll_card1.setVisibility(VISIBLE);
                ll_card2.setVisibility(VISIBLE);
                ll_no_data.setVisibility(GONE);
                guideShow();
            }
            p2 = roundDouble(data.goldBuyPercent);//正面
            p1 = roundDouble(data.goldSellPercent);
            p2_2 = roundDouble(data.silverBuyPercent);//反面
            p1_2 = roundDouble(data.silverSellPercent);

            q2 = roundDouble(data.goldOpenPercent);
            q1 = roundDouble(data.goldClosePercent);
            q2_2 = roundDouble(data.silverOpenPercent);
            q1_2 = roundDouble(data.silverClosePercent);

            refreshUpdateTime(data.lastestTime);
            refreshCard();
        }
    }

    /**
     * 保留2个小数，然后返回double
     */
    private double roundDouble(double param) {
        BigDecimal bg = new BigDecimal(param);
        double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return f1;
    }

    private void refreshUpdateTime(String time) {

        //按照UI的要求，把时间格式改一下
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date d = sdf.parse(time);
            sdf = new SimpleDateFormat("MM-dd HH:mm");
            time = sdf.format(d);
        } catch (java.text.ParseException e) {
            e.printStackTrace();
        }
        //更新刷新时间
        TextView tv_update_time = (TextView) findViewById(R.id.tv_update_time);
        tv_update_time.setText(time + " 更新");
    }

    private void initData() {
        //第一个卡片的正反面数据
        //卡片正面
        p1 = 0.1f;
        p2 = 0.9f;
        //卡片正面反面
        p1_2 = 1.0f;
        p2_2 = 0.0f;

        //第二个卡片的正反面数据
        q1 = 0.66f;
        q2 = 0.34f;
        //卡片正面反面
        q1_2 = 0.34f;
        q2_2 = 0.66f;
    }

    private void refreshSuggestBuySell(float p1, float p2, TextView textView) {//p1,空，p2 多
    /*            显示说明：
    A ） 空或多范围在48%~52%，文案显示：多空交战
    B） 空或多范围在53~65%，且空>多，文案显示：市场偏空
    C） 空或多范围在53~65%，且多>空，文案显示：市场偏多
    D） 空 ≥ 66%，文案显示：极端看空
    E） 多 ≥ 66%，文案显示：极端看多*/
        String TEMP = "多空交战";
        String s;
        //逻辑重写
        if (p1 > p2) {// 如果"空"大于"多"
            if (p1 <= 0.52f) {
                s = TEMP;
            } else if (p1 <= 0.65f) {
                s = "市场偏空";
            } else {
                s = "极端看空";
            }
        } else if (p2 > p1) {
            if (p2 <= 0.52f) {
                s = TEMP;
            } else if (p2 <= 0.65f) {
                s = "市场偏多";
            } else {
                s = "极端看多";
            }
        } else {
            s = TEMP;
        }
        Log.d("ppax", "" + p1 + "-" + p2 + "-" + s);
        // 要检查是不是有空档,那就用循环来打印吧
        if (textView != null)
            textView.setText(s);
    }


    private void refreshSuggestOpenClose(float p1, float p2, TextView textView) {//p1,平仓，p2 持仓
    /*
        文案显示规则
    A ） 持仓或平仓范围在48%~52%，文案显示：区间交易
    B） 持仓或平仓范围在53~65%，且持仓>平仓，文案显示：长线布局
    C） 持仓或平仓范围在53~65%，且平仓>持仓，文案显示：获利出场
    D） 持仓 ≥ 66%，文案显示：看好后市
    E） 平仓 ≥ 66%，文案显示：重新布局*/

        String TEMP = "区间交易";
        String s;
        //逻辑重写
        if (p1 > p2) {// 如果"平仓"大于"持仓"
            if (p1 <= 0.52f) {
                s = TEMP;
            } else if (p1 <= 0.65f) {
                s = "获利出场";
            } else {
                s = "重新布局";
            }
        } else if (p2 > p1) {
            if (p2 <= 0.52f) {
                s = TEMP;
            } else if (p2 <= 0.65f) {
                s = "长线布局";
            } else {
                s = "看好后市";
            }
        } else {
            s = TEMP;
        }

        textView.setText(s);
    }

    // 翻转卡片
    public void flipCard(CardViewHolder holder, View mFlCardFront, View mFlCardBack, int pageIndex) {
        setLis(new MyAnimatorListenerAdapter(holder));
        // 正面朝上
        if (pageIndex == 0) {
            mFrontOutSet.setTarget(mFlCardFront);
            mBackInSet.setTarget(mFlCardBack);

            mFrontOutSet.start();
            mBackInSet.start();
        } else { // 背面朝上
            mFrontInSet.setTarget(mFlCardFront);
            mBackOutSet.setTarget(mFlCardBack);

            mFrontInSet.start();
            mBackOutSet.start();
        }
    }

    private AnimatorSet mFrontOutSet, mFrontInSet;
    private AnimatorSet mBackOutSet, mBackInSet;

    class MyAnimatorListenerAdapter extends AnimatorListenerAdapter {
        CardViewHolder holder;

        MyAnimatorListenerAdapter(CardViewHolder holder) {
            this.holder = holder;
        }

        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            ifAnimatorRunning = true;

            dealAniException(holder);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            ifAnimatorRunning = false;
            holder.tv_p1.setVisibility(VISIBLE);
            holder.tv_p2.setVisibility(VISIBLE);
            holder.tv_p1_2.setVisibility(VISIBLE);
            holder.tv_p2_2.setVisibility(VISIBLE);
        }

    }

    // 设置动画
    private void setAnimators() {
        mFrontOutSet = (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.front_anim_out);
        mFrontInSet = (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.front_anim_in);

        mBackOutSet = (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.back_anim_out);
        mBackInSet = (AnimatorSet) AnimatorInflater.loadAnimator(mContext, R.animator.back_anim_in);

        //设置插值器
        mFrontOutSet.setInterpolator(new LinearInterpolator());
        mFrontInSet.setInterpolator(new LinearInterpolator());
        mBackOutSet.setInterpolator(new LinearInterpolator());
        mBackInSet.setInterpolator(new LinearInterpolator());
    }

    private void setLis(AnimatorListenerAdapter animatorListenerAdapter) {
        mFrontOutSet.removeAllListeners();
        mFrontInSet.removeAllListeners();
        mBackOutSet.removeAllListeners();
        mBackInSet.removeAllListeners();
        // 设置监听事件
        mFrontOutSet.addListener(animatorListenerAdapter);
        mFrontInSet.addListener(animatorListenerAdapter);
        mBackOutSet.addListener(animatorListenerAdapter);
        mBackInSet.addListener(animatorListenerAdapter);
    }

    // 改变视角距离, 贴近屏幕,这个必须设置，因为如果不这么做，沿着Y轴旋转的过程中有可能产生超出屏幕的3D效果。
    private void setCameraDistance(View mFlCardFront, View mFlCardBack) {
        int distance = 16000;
        float scale = getResources().getDisplayMetrics().density * distance;
        mFlCardFront.setCameraDistance(scale);
        mFlCardBack.setCameraDistance(scale);
    }

    private void dealAniException(CardViewHolder holder) {
        // 当前手机的型号
        //-TODO- 如果发现是某些特殊机型，不支持 LinearLayout的weigh的话，那就··让它消失吧;
        Log.d("BRANDTag", "" + Build.BRAND + "-" + Build.MODEL);
        if (Build.BRAND.equals("OPPO") && Build.MODEL.equals("OPPO R9s")) {//目前只发现在OPPO R9S机器上旋转动画居然会有部分空间会闪一闪，以后如果发现了其他机器也有问题，就加进来吧；
            holder.tv_p1.setVisibility(INVISIBLE);
            holder.tv_p2.setVisibility(INVISIBLE);
            holder.tv_p1_2.setVisibility(INVISIBLE);
            holder.tv_p2_2.setVisibility(INVISIBLE);
        }
    }

    public void refreshDataForDemo(float p1, float p1_2, float q1, float q1_2) {// 正面的看空，反面的看空(对应的看多数据，用1直接减去它)
        if (p1 < 0 || p1 > 1) return;
        if (p1_2 < 0 || p1_2 > 1) return;
        initData();
        this.p1 = p1;
        this.p2 = 1 - p1;
        this.p1_2 = p1_2;
        this.p2_2 = 1 - p1_2;
        this.q1 = q1;
        this.q2 = 1 - q1;
        this.q1_2 = q1_2;
        this.q2_2 = 1 - q1_2;
        refreshUpdateTime("调试模式，模拟数据！");
        refreshCard();
    }

    //引导icon的动画,上下浮动
    private void startGuideAnim() {
        TranslateAnimation anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0.1F, Animation.RELATIVE_TO_SELF, 0F);
        anim.setDuration(500);
        anim.setInterpolator(new DecelerateInterpolator());
        anim.setRepeatMode(Animation.REVERSE);
        anim.setRepeatCount(Animation.INFINITE);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {


            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });

        iv_card_guidance.startAnimation(anim);
    }


    /**
     * 判断条件看是否要显示
     */
    private void guideShow() {
        String ifGuideClosedStr = CacheUtils.readFile(ifGuideClosedTag);//每次都从缓存文件中取
        if (TextUtils.isEmpty(ifGuideClosedStr)) {
            ifGuideClosed = false;
        } else {
            ifGuideClosed = Boolean.valueOf(ifGuideClosedStr.trim());
        }
        //rl_card_guidance 这个东西 一次app运行只显示一次，后来的，就算是这个布局被重新实例化，也不要显示
        Log.d("ifGuideClosed", "" + ifGuideClosed);
        if (!ifGuideClosed) {
            rl_card_guidance.setVisibility(VISIBLE);
            startGuideAnim();
        } else {
            rl_card_guidance.setVisibility(GONE);
        }
    }

    private void guideHide() {
        rl_card_guidance.setVisibility(GONE);
    }

}
